package com.thinqq.web.client.content.painter;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.thinqq.web.client.ThinqQImageBundle;
import com.thinqq.web.client.constants.CSSConstants;
import com.thinqq.web.client.content.ProductDevelopment;
import com.thinqq.web.client.content.ThinqqHome;
import com.thinqq.web.client.content.handler.LinkClickHandler;

public class ThinqQHomeContentPainter implements IContentPainter {

	@Override
	public void updateConent(HorizontalPanel mainContent,
			VerticalPanel relatedContent) {
		mainContent.clear();
		ThinqQImageBundle imageBundle = GWT.create(ThinqQImageBundle.class);
		ThinqqHome content = GWT.create(ThinqqHome.class);
		VerticalPanel root = new VerticalPanel();
		HorizontalPanel main = new HorizontalPanel();
		root.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		Label title = new Label(content.heading());
		title.setStyleName(CSSConstants.CSS_MAIN_CONTENT_TITLE);
		root.add(title);
		Label introText = new Label(content.introText());
		introText.addStyleName(CSSConstants.BOTTOM_MARGIN_5);
		root.add(introText);
	
		Grid servicesGrid = new Grid(2,2);
		servicesGrid.setCellSpacing(10);
		
		Image itImage = new Image(imageBundle.getITSmallImage());
		itImage.addStyleName(CSSConstants.IMAGE_LINK);
		itImage.addClickHandler(new LinkClickHandler(ContentPainterRegistry.getContentPainter(ContentPainterRegistry.IT_CONTENT), mainContent, relatedContent));
		servicesGrid.setWidget(0,0,itImage);
		VerticalPanel itPanel = new VerticalPanel();
		itPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		Label inforTech = new Label(content.infoTech());
		inforTech.setStyleName(CSSConstants.SUB_TITLE);
		itPanel.add(inforTech);
		itPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		itPanel.add(new Label(content.itcontent()));
		//servicesGrid.getCellFormatter().setAlignment(0,1, HasHorizontalAlignment.ALIGN_JUSTIFY, HasVerticalAlignment.ALIGN_TOP);
		servicesGrid.setWidget(0,1,itPanel);
		
		Image pdImage = new Image(imageBundle.getPDSmallImage());
		pdImage.addStyleName(CSSConstants.IMAGE_LINK);
		pdImage.addClickHandler(new LinkClickHandler(ContentPainterRegistry.getContentPainter(ContentPainterRegistry.PD_CONTENT), mainContent, relatedContent));
		servicesGrid.setWidget(1,0,pdImage);
		VerticalPanel pdPanel = new VerticalPanel();
		pdPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		Label prodDev = new Label(content.prodDev());
		prodDev.setStyleName(CSSConstants.SUB_TITLE);
		pdPanel.add(prodDev);
		pdPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		pdPanel.add(new Label(content.pdcontent()));
		//servicesGrid.getCellFormatter().setAlignment(1,1, HasHorizontalAlignment.ALIGN_JUSTIFY, HasVerticalAlignment.ALIGN_TOP);
		servicesGrid.setWidget(1,1,pdPanel);
		main.add(servicesGrid);
		HorizontalPanel adpanel = new HorizontalPanel();
		Grid ads = new Grid(3,1);
		ads.setCellSpacing(5);
		adpanel.addStyleName(CSSConstants.ADS_GRID);
		HorizontalPanel adpanel1 = new HorizontalPanel();
		adpanel1.addStyleName(CSSConstants.ADS);
		adpanel1.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		Image siisSmallImage = new Image(imageBundle.getSIISUltraSmallImage());
		siisSmallImage.setStyleName(CSSConstants.IMAGE_LINK);
		siisSmallImage.addClickHandler(new LinkClickHandler(ContentPainterRegistry.getContentPainter(ContentPainterRegistry.SIIS), mainContent, relatedContent));		
		adpanel1.add(siisSmallImage);
		adpanel1.add(new Label(content.siis()));
		HorizontalPanel adpanel2 = new HorizontalPanel();
		adpanel2.addStyleName(CSSConstants.ADS);
		adpanel2.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		adpanel2.add(new Image(imageBundle.getCloudUltraSmallImage()));
		adpanel2.add(new Label(content.cloudAd()));
		HorizontalPanel adpanel3 = new HorizontalPanel();
		adpanel3.addStyleName(CSSConstants.ADS);
		adpanel3.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		adpanel3.add(new Image(imageBundle.getBusinessUltraSmallImage()));
		adpanel3.add(new Label(content.effectiveBusiness()));
		ads.setWidget(0,0, adpanel1);
		ads.setWidget(1,0, adpanel2);
		ads.setWidget(2,0, adpanel3);
		adpanel.add(ads);
		main.add(adpanel);
		root.add(main);
		mainContent.add(root);

	}

}
